package offer.singleLinkedList;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 23:41
 */
public class ReverseLinkedList16 {

    public static <T> LinkedList<T> reverseList(LinkedList<T> list){
        if (list == null || list.getNext() == null)
            return list;
        LinkedList<T> head = list;
        LinkedList<T>  next = list.getNext();
        LinkedList<T> temp = next.getNext();

        head.setNext(null);
        while (next != null){
            next.setNext(head);
            head = next;
            next = temp;
            if (temp != null)
                temp = temp.getNext();
        }
        return head;
    }
}
